package com.maduar.demo.algo.interview.dp;

/**
 * Description:
 *
 * @author maduar maduar@163.com
 * @date 2021-04-05 19:40
 */
public class SlideWindow {

    public static int[] getSlideWindow(int[] nums, int k) {
        if(k == 1) {
            return nums;
        }

        int len = nums.length;
        if(k >= len) {
            return new int[]{getMaxNumber(nums)};
        }

        int range = len - k;
        int[] res = new int[range + 1];
        for (int i = 0; i <= len - k; i++) {
            System.out.println(i + " " + nums[i]);
            int c = i;
            int maxLen = c + k;
            int max = nums[i];
            while (c < maxLen) {
                max = Math.max(max, nums[c]);
                c++;
            }
            res[i] = max;
        }

        return res;
    }

    private static int getMaxNumber(int[] nums) {
        int max = nums[0];
        for (int num : nums) {
            max = Math.max(max, num);
        }

        return max;
    }

    //[3, 3, -1, 5, 0, 0]
}
